﻿using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

namespace DailyDiet.Services.Navigation
{
    /// <summary>
    /// 页面激活页
    /// </summary>
    public class ContentPageActivationService : IContentPageActivationService
    {
        //*******私有变量
        /// <summary>
        /// 页面缓存
        /// </summary>
        private Dictionary<string, ContentPage> _cache =
            new Dictionary<string, ContentPage>();

        public ContentPage Activate(string pageKey) => 
            _cache.ContainsKey(pageKey) 
                ? _cache[pageKey]
                : (_cache[pageKey] = (ContentPage)Activator.CreateInstance(
                    ContentNavigationServiceConstants.PageKeyTypeDictionary[pageKey]));
    }
}
